Stockname = char(Stockname);
Indexname = char(Indexname);
[Stock Index Date PriceStock PriceIndex] = getStock_Index(Stockname,Indexname);
rStock = PriceStock(2:end)./PriceStock(1:end-1) - 1;
rIndex = PriceIndex(2:end)./PriceIndex(1:end-1) - 1;
%-----------------------------------------------------------
%Estimation OLS 1Year
%-----------------------------------------------------------
%Rolling window
rolling = 260;
[n,m] = size(rStock);
k = n-rolling;
datan = x2mdate(Date,0)
datam=datan(262:end)
for i = 1:k
    j = i+260;
    rStockOls = rStock(i:j,1);
    rIndexOls = rIndex(i:j,:);
    [n,m] = size(rStockOls);
    X = [ones(n,1),rIndexOls];
    y = rStockOls;
    %QR Decomposition X
    [Q,R] = qr(X,0);
    %Regression Coefficients 
    betaOLS = R\(Q'*y);
    %Calculate beta for graph
    betaOLS_Graph(i,:) = (R\(Q'*y))';
end
%---Output to Excell
ExcelOLS=[datam,betaOLS_Graph(:,2)];